home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Symantec Versions / C04 Speech / P03 Input Speech / InputSpeech.c next >
Encoding:
C/C++ Source or Header  |  1995-08-31  |  2.6 KB  |  123 lines  |  [TEXT/KAHL]

  1. //____________________________________________________________
  2. //    InputSpeech.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include <Speech.h>
  13.  
  14.  
  15. //____________________________________________________________
  16.  
  17. void     InitializeToolbox( void );
  18. Boolean  IsSpeechAvailable( void );
  19. void     OpenSpeechDialog( void );
  20.  
  21.  
  22. //____________________________________________________________
  23.  
  24. #define        rSpeechDialog       128
  25. #define        kSpeakButton          1
  26. #define        kQuitButton           2
  27. #define        kPhraseEdit           3
  28.  
  29.  
  30. //____________________________________________________________
  31.  
  32. void  main( void )
  33.    Boolean  speechPresent;
  34.  
  35.    InitializeToolbox();
  36.  
  37.    speechPresent = IsSpeechAvailable();
  38.    if ( speechPresent == false )
  39.       ExitToShell();
  40.  
  41.    OpenSpeechDialog();
  42. }
  43.  
  44.  
  45. //____________________________________________________________
  46.  
  47. void  OpenSpeechDialog( void )
  48. {
  49.    DialogPtr  theDialog;
  50.    short      theItem;
  51.    Boolean    allDone = false;
  52.    short      theType;    
  53.    Handle     theHandle;              
  54.    Rect       theRect;     
  55.    Str255     theString;
  56.    OSErr      theError;
  57.    
  58.    theDialog = GetNewDialog( rSpeechDialog, nil, (WindowPtr)-1L );
  59.    ShowWindow( theDialog );
  60.    SetPort( theDialog );
  61.    
  62.    while ( allDone == false )
  63.    {
  64.       ModalDialog( nil, &theItem );
  65.          
  66.       switch ( theItem )
  67.       {
  68.          case kSpeakButton:
  69.             GetDialogItem( theDialog, kPhraseEdit, &theType, &theHandle, &theRect ); 
  70.             GetDialogItemText( theHandle, theString );
  71.             theError = SpeakString( theString );
  72.             if ( theError != noErr )
  73.                ExitToShell();
  74.             break;
  75.  
  76.          case kQuitButton:
  77.             allDone = true;
  78.             break;
  79.       }
  80.    }
  81.    
  82.    DisposeDialog( theDialog ); 
  83. }
  84.  
  85.  
  86. //____________________________________________________________
  87.  
  88. Boolean  IsSpeechAvailable( void )
  89. {
  90.    OSErr    theError;
  91.    long     theResult;
  92.    Boolean  speechAvail;
  93.    
  94.    theError = Gestalt( gestaltSpeechAttr, &theResult );
  95.    if ( theError != noErr )
  96.       ExitToShell();
  97.       
  98.    speechAvail = theResult & ( 1 << gestaltSpeechMgrPresent );  
  99.    if ( speechAvail > 0 )
  100.       return ( true );
  101.    else
  102.       return ( false );
  103. }
  104.  
  105.  
  106. //____________________________________________________________
  107.  
  108. void  InitializeToolbox( void )
  109. {
  110.    InitGraf( &qd.thePort );
  111.    InitFonts();
  112.    InitWindows();
  113.    InitMenus();
  114.    TEInit();
  115.    InitDialogs( 0L );
  116.    FlushEvents( everyEvent, 0 );
  117.    InitCursor();
  118. }
  119.  
  120.  
  121.  
  122.